import java.util.ArrayList;
import java.util.List;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.builder.xml.Namespaces;
import org.apache.camel.builder.xml.XPathBuilder;
import org.apache.camel.component.file.FileComponent;
import org.apache.camel.impl.DefaultCamelContext;


public class AppMain {
	public static void main(String [] args) throws Exception {
		
		
		
		CamelContext contextPotsdam = new DefaultCamelContext();		
		contextPotsdam.addRoutes(new RouteBuilder() 
		{
			public void configure() {
				
//				from("rss:http://geofon.gfz-potsdam.de/db/eqinfo.php?fmt=rss&splitEntries=false").marshal().rss().to("file:data/splittedPotsdam");
			
//				from("rss:http://geofon.gfz-potsdam.de/db/eqinfo.php?fmt=rss&splitEntries=false").marshal().rss().split(xpath("/rss/channel/item")).convertBodyTo(String.class).to("file:data/splittedPotsdam");
				
//				XPathBuilder xPathBuilder = new XPathBuilder("/rss/channel/item"); 
//				from("rss:http://geofon.gfz-potsdam.de/db/eqinfo.php?fmt=rss&splitEntries=false").marshal().rss().split(xPathBuilder).parallelProcessing().to("file:data/splittedPotsdam");

				
//				from("direct:start").process(new Processor() {
//				    public void process(Exchange exchange) throws Exception{
//				        Message in = exchange.getIn();
//				        in.setBody(in.getBody(String.class) + " World!");
//				    }
//				}).to("mock:result");
				
				from("rss:http://geofon.gfz-potsdam.de/db/eqinfo.php?fmt=rss&splitEntries=false")
				.marshal()
				.rss()
		        // here we use a POJO bean mySplitterBean to do the split of the payload
		        .split().method("MySplitter", "splitBody")
		        .to("file:data/splittedPotsdam");


				
			}
		});
		
//		CamelContext contextUSGS = new DefaultCamelContext();		
//		contextPotsdam.addRoutes(new RouteBuilder() 
//		{
//			public void configure() {
//				
//				from("rss:http://earthquake.usgs.gov/earthquakes/catalogs/eqs1day-M2.5.xml?splitEntries=false").marshal().rss().to("file:data/");
//				
//			
//			}
//		});
		
		contextPotsdam.start();
//		contextUSGS.start();
		
		Thread.sleep(7500);
		
		contextPotsdam.stop();
//		contextUSGS.stop();
	}
}


